package com.yuqing.myblogServe.common.lang;

import java.util.List;

/**
 * @author lyq
 * @date 2023/12/9
 **/
public class PageBean<T> {
    private long pageNum;
    private long pageSize;
    private long total;
    private List<? extends T> list;

    public PageBean(long pageNum, long pageSize, long total, List<T> list) {
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.total = total;
        this.list = list;
    }

    public static <T> PageBean<T> of(long pageNum, long pageSize, long total, List<T> list) {
        return new PageBean(pageNum, pageSize, total, list);
    }

    public long getPages() {
        if (this.pageSize == 0L) {
            return 0L;
        } else {
            long pages = this.getTotal() / this.pageSize;
            if (this.getTotal() % this.pageSize != 0L) {
                ++pages;
            }

            return pages;
        }
    }

    public long getPageNum() {
        return this.pageNum;
    }

    public long getPageSize() {
        return this.pageSize;
    }

    public long getTotal() {
        return this.total;
    }

    public List<? extends T> getList() {
        return this.list;
    }

    public void setPageNum(long pageNum) {
        this.pageNum = pageNum;
    }

    public void setPageSize(long pageSize) {
        this.pageSize = pageSize;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public void setList(List<? extends T> list) {
        this.list = list;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof PageBean)) {
            return false;
        } else {
            PageBean<?> other = (PageBean)o;
            if (!other.canEqual(this)) {
                return false;
            } else if (this.getPageNum() != other.getPageNum()) {
                return false;
            } else if (this.getPageSize() != other.getPageSize()) {
                return false;
            } else if (this.getTotal() != other.getTotal()) {
                return false;
            } else {
                Object this$list = this.getList();
                Object other$list = other.getList();
                if (this$list == null) {
                    if (other$list != null) {
                        return false;
                    }
                } else if (!this$list.equals(other$list)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof PageBean;
    }

//    public int hashCode() {
//        Boolean PRIME = true;
//        int result = 1;
//        long $pageNum = this.getPageNum();
//        int result = result * 59 + (int)($pageNum >>> 32 ^ $pageNum);
//        long $pageSize = this.getPageSize();
//        result = result * 59 + (int)($pageSize >>> 32 ^ $pageSize);
//        long $total = this.getTotal();
//        result = result * 59 + (int)($total >>> 32 ^ $total);
//        Object $list = this.getList();
//        result = result * 59 + ($list == null ? 43 : $list.hashCode());
//        return result;
//    }

    public String toString() {
        return "PageBean(pageNum=" + this.getPageNum() + ", pageSize=" + this.getPageSize() + ", total=" + this.getTotal() + ", list=" + this.getList() + ")";
    }
}
